package com.ssm.lzh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.hj.page.Page;
import com.ssm.lzh.serachId.SerachId;
import com.ssm.lzh.service.FoodService;
import com.ssm.mapper.FoodMapper;
import com.ssm.pojo.Food;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class FoodServiceImpl implements FoodService {


    @Resource
    public FoodMapper foodMapper;

    @Resource
    private SerachId serachId;

    @Override
    public PageInfo<Food> queryAllFood(Page<Food> page) {
        PageHelper.startPage(page.getPageNum(),page.getPageSize());

        return new PageInfo<Food>(this.foodMapper.queryAllFood(page.getSearchObj()));
    }

    @Override
    public int addFood(Food food) {

        String sp = serachId.ccid("SP");
        food.setFoodid(sp);
        return this.foodMapper.addFood(food);
    }

    @Override
    public int updateFood(Food food) {
        return this.foodMapper.updateFood(food);
    }

    @Override
    public int deleteFood(String id) {
        return this.foodMapper.deleteFoodByid(id);
    }
}
